package cn.tedu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

public class ReJDBC {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement ps=null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql:///cgb2104","root","12341234");
            String name = new Scanner(System.in).nextLine();
            String password = new Scanner(System.in).nextLine();
            String sql = "select * from user2 where name =? and password = ?";
            ps = conn.prepareStatement(sql);//得先有对象，才能赋值--不然会报空指针异常
            ps.setString(1,name);
            ps.setString(2,password);

            rs = ps.executeQuery();
            if (rs.next()){
                System.out.println("登录成功 ");
            }else {
                System.out.println("登录失败 ");
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JDBC_Utils.close(conn,ps,rs);
        }
    }
}
